<?php
namespace Admin\Controller;
use Think\Controller;

/**
 * 控制器基类
 * Class AbstractController
 * @package Admin\Controller
 */
class AbstractController extends Controller {

    protected function  _initialize(){
        $session_user_id=session('USER_ID');
        if(!empty($session_user_id)){
            //todo:验证访问权限
        }else{
            if(IS_AJAX){
                $this->error("您还没有登录！",U("Admin/Public/login"));
            }else{
                redirect(U("Admin/Public/login"));
                exit();
            }
        }
    }

    protected function page($total_size = 1, $page_size = 0, $current_page = 1, $listRows = 6, $pageParam = '', $pageLink = '', $static = false) {
        if ($page_size == 0) {
            $page_size = C("PAGE_LISTROWS");
        }

        if (empty($pageParam)) {
            $pageParam = C("VAR_PAGE");
        }

        $page = new \Think\Page($total_size, $page_size, $current_page, $listRows, $pageParam, $pageLink, $static);
        $page->SetPager('Admin', '{first}{prev}&nbsp;{liststart}{list}&nbsp;{next}{last}<span>共{recordcount}条数据</span>', array("listlong" => "4", "first" => "首页", "last" => "尾页", "prev" => "上一页", "next" => "下一页", "list" => "*", "disabledclass" => ""));
        return $page;
    }

     //创建目录
    function mkdirs($dir)
    {
        if(!is_dir($dir))
        {
        if(!$this->mkdirs(dirname($dir))){
        return false;
        }
        if(!mkdir($dir,0777)){
        return false;
        }
        }
        chmod($dir, 777);    //给目录操作权限
        return true; 
    }

}